home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conqbat.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  214 lines

  1. #define new(x) x=(tplanet *)alloc(sizeof(tplanet))
  2. #include <stdio.h>
  3. #include "defs.h"
  4. #include "structs.h"
  5. #include "vars.h"
  6.  
  7. double exp(), log(), fmin();
  8.  
  9. blast(planet, factors)
  10. tplanet *planet;
  11. {
  12.         int killed;
  13.  
  14.         killed = min(planet->capacity,factors / 4);
  15.         planet->inhabitants = min(planet->inhabitants, planet->capacity) - killed;
  16.         planet->iu = min(planet->iu - killed, planet->inhabitants * iu_ratio);
  17.         planet->capacity = planet->capacity - killed;
  18.         if ( planet->inhabitants <=0 ) {
  19.                 planet->inhabitants = 0;
  20.                 planet->iu = 0;
  21.                 planet->mb = 0;
  22.                 planet->amb = 0;
  23.                 if ( planet->team != none ) {
  24.                         col_stars[planet->pstar][planet->team]--;
  25.                         planet->team = none;
  26.                         planet->esee_team = none;
  27.                         planet->conquered = false;
  28.                         on_board(stars[planet->pstar].x,
  29.                                         stars[planet->pstar].y);
  30.                 };
  31.         };
  32. }
  33.  
  34.  
  35.  
  36. fire_salvo(att_team, task, tfnum, planet, first_time)
  37. tteam att_team;
  38. struct sttf *task;
  39. struct stplanet *planet;
  40. boolean first_time;
  41. {
  42.         int bases,att_forces,def_forces; 
  43.         boolean a_lose_none,p_lose_none;
  44.         float    att_odds, def_odds,attack_save,defend_save;
  45.         tteam def_team;
  46.         if ( left_line[24] ) {
  47.                 point(1,24);
  48.                 printf(blank_line);
  49.                 left_line[24] = false;
  50.         };
  51.         if ( att_team==ENEMY )
  52.                 def_team = player;
  53.         else
  54.                 def_team = ENEMY;
  55.         att_forces = weapons[att_team]*(task->c*c_guns + task->b*b_guns);
  56.         def_forces = weapons[def_team]*(planet->mb*c_guns+planet->amb*b_guns);
  57.         if ( def_forces > 0 ) {
  58.                 att_odds = fmin ( (((float) def_forces) / att_forces) , 14.0);
  59.                 attack_save = exp(log(0.8) * (att_odds));
  60.                 def_odds = fmin( (float)att_forces/def_forces, 14.0);
  61.                 defend_save=exp(log(0.8)* (def_odds));
  62.                 point(1,20);
  63.                 if ( att_team == player )
  64.                         printf("TF%c", tfnum+'a'-1);
  65.                 else
  66.                         printf(" EN");
  67.                 printf(": %4d(weap %2d)sur: %4.0f", att_forces, 
  68.                         weapons[att_team], attack_save*100);
  69.                 point(1,21);
  70.                 printf(" %c%d:%4d (weap %2d)sur: %4.0f", planet->pstar+'A'-1,
  71.                 planet->number,
  72.                 def_forces, weapons[def_team], defend_save*100);
  73.                 point(1,22);
  74.                 printf("Attacker losses:              ");
  75.                 point(1,23);
  76.                 left_line[23]=true;
  77.                 printf(" Planet losses :              ");
  78.                 a_lose_none = true;
  79.                 p_lose_none = true;
  80.                 do {
  81.                         point(17,22);
  82.                         lose(&task->c,&a_lose_none,'c',attack_save);
  83.                         lose(&task->b,&a_lose_none,'b',attack_save);
  84.                         point(17,23);
  85.                         bases = planet->mb;
  86.                         lose(&planet->mb,&p_lose_none,'m',defend_save);
  87.                         if ( planet->mb != bases ) printf("b");
  88.                         bases = planet->amb;
  89.                         lose(&planet->amb,&p_lose_none,'a',defend_save);
  90.                         if ( planet->amb != bases ) printf("mb");
  91.                 } 
  92.                 while (!first_time && p_lose_none &&
  93.                     a_lose_none);
  94.                 if ( a_lose_none ) {
  95.                         point(17,22);
  96.                         printf("(none)");
  97.                 };
  98.                 if ( p_lose_none ) {
  99.                         point(17,23);
  100.                         printf("(none)");
  101.                 };
  102.         };
  103.         if ( (planet->mb+planet->amb==0)&& (any_bc(att_team,planet->pstar)) ) {
  104.                 point(1,24);
  105.                 printf("Planet %d falls!               ", planet->number);
  106.                 planet->team = att_team;
  107.                 planet->esee_team = att_team;
  108.                 planet->conquered = true;
  109.                 col_stars[task->dest][def_team]--;
  110.                 col_stars[task->dest][att_team]++;
  111.                 point(50,1);
  112.                 pr5nt_star(planet->pstar);
  113.                 clear_field();
  114.                 on_board(stars[task->dest].x, stars[task->dest].y);
  115.         };
  116. }
  117.  
  118. play_salvo(starnum, Battl9)
  119. int starnum;
  120. boolean *Battl9;
  121. {
  122.         boolean battle;
  123.         char tf_char,planch; 
  124.         int planet_num,tf_num; 
  125.         boolean found;
  126.         struct stplanet *pplanet;
  127.         boolean first_time;
  128.         battle = *Battl9;
  129.         printf("Attack planet ");
  130.         pplanet = stars[starnum].first_planet;
  131.         if ( (col_stars[starnum][ENEMY]>1) ) {
  132.                 printf(":");
  133.                 get_char(&planch);
  134.                 cle3r_left();
  135.                 planet_num = planch - '0';
  136.                 found = false;
  137.                 while (!found) {
  138.                         if (pplanet->number == planet_num)
  139.                                 found = true;
  140.                         else {
  141.                                 if (pplanet->next == nil)
  142.                                         found = true;
  143.                                 else
  144.                                         pplanet = pplanet->next;
  145.                         }
  146.                 }
  147.                 if ( pplanet->number != planet_num ) {
  148.                         planet_num = 0;
  149.                         error_message();
  150.                         printf("! That is not a useable planet");
  151.                 } 
  152.                 else if ( pplanet->team != ENEMY ) {
  153.                         error_message();
  154.                         printf(" !Not an enemy colony");
  155.                         planet_num = 0;
  156.                 };
  157.         } 
  158.         else {
  159.                 while ( pplanet->team != ENEMY )
  160.                         pplanet = pplanet->next;
  161.                 printf("%d", pplanet->number);
  162.                 cle3r_left();
  163.         };
  164.         if ( planet_num != 0 ) {
  165.                 point(1,19);
  166.                 printf(" attacking tf ");
  167.                 if ( tf_stars[starnum][player]>1 ) {
  168.                         printf(":");
  169.                         get_char(&tf_char);
  170.                         tf_num = tf_char-'A'+1;
  171.                 } 
  172.                 else {
  173.                         tf_num = 1;
  174.                         while (tf[player][tf_num].dest != starnum ||
  175.                             tf[player][tf_num].eta != 0 )  
  176.                                 tf_num++;
  177.                         putchar(tf_num+'a'-1);
  178.                 }
  179.                 if (tf_num <1 || tf_num >26) {
  180.                         error_message();
  181.                         printf(" !Illegal tf");
  182.                 }
  183.                 else if ( tf[player][tf_num].dest==0 ) {
  184.                         error_message();
  185.                         printf(" !Nonexistent tf");
  186.                 }
  187.                 else if ( (tf[player][tf_num].dest!=starnum) ||
  188.                     (tf[player][tf_num].eta!=0) ) {
  189.                         error_message();
  190.                         printf(" !Tf is not at this star      ");
  191.                 }
  192.                 else if ( (tf[player][tf_num].b+tf[player][tf_num].c)==0 )  {
  193.                         error_message();
  194.                         printf(" !Tf has no warships");
  195.                 }
  196.                 else {
  197.                         first_time = ! pplanet->under_attack;
  198.                         if ( ! (pplanet->under_attack) ) {
  199.                                 pplanet->under_attack = true;
  200.                                 point(50,1);
  201.                                 pr5nt_star(starnum);
  202.                                 clear_field();
  203.                         };
  204.                         fire_salvo(player,&tf[player][tf_num],tf_num,
  205.                                 pplanet,first_time);
  206.                         zero_tf(player,tf_num);
  207.                         battle = (col_stars[starnum][ENEMY]>0) && 
  208.                                         (any_bc(player,starnum));
  209.                 };
  210.         };
  211.         *Battl9 = battle;
  212. }
  213.  
  214.